<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
include '../operations/connection.php';	

$idAssets=$_REQUEST['idAssets'];
$nameAssets=rawurldecode($_REQUEST['nameAssets']);
$countAssets=$_REQUEST['countAssets'];
$notuseAssets=$_REQUEST['notuseAssets'];
$stockAssets=$_REQUEST['stockAssets'];

$groupAssets=$_REQUEST['groupAssets'];
$typeAssets=$_REQUEST['typeAssets'];


mysql_query("UPDATE `assets` SET `count`=`count`-'".$countAssets."', `stock`=`stock`-'".$stockAssets."', `notuse`=`notuse`-'".$notuseAssets."',creater='".$_SESSION['IDEmployee']."', datetime=NOW() WHERE (`id`='".$idAssets."')");

$result=mysql_query("SELECT * FROM assets a WHERE a.`name`='".$nameAssets."' AND a.`type`='".$typeAssets."' AND a.`group`='".$groupAssets."';");
$i=0;
while ($r=mysql_fetch_array($result)){
	$i++;
}
if($i==0)
	mysql_query("INSERT INTO assets (`name`,count,stock,notuse,`group`,type,`note`,creater,datetime) VALUES ('".$nameAssets."', '".$countAssets."', '".$stockAssets."', '".$notuseAssets."', '".$groupAssets."','".$typeAssets."', 'move', '".$_SESSION['IDEmployee']."',NOW())");
else
	mysql_query("UPDATE `assets` SET `count`=`count`+'".$countAssets."', `stock`=`stock`+'".$stockAssets."', `notuse`=`notuse`+'".$notuseAssets."',`group`='".$groupAssets."',creater='".$_SESSION['IDEmployee']."', datetime=NOW() WHERE `name`='".$nameAssets."' AND `type`='".$typeAssets."' AND `group`='".$groupAssets."';");

//mysql_query("DELETE FROM `assets` WHERE `count`=0 AND `stock`=0 AND `notuse`=0");

mysql_close($connection);
?>